home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Imágenes y mapas de bits / Wink / Wink.cs < prev    next >
Encoding:
Text File  |  2002-05-06  |  1.4 KB  |  50 lines

  1. //------------- ----------------------
  2. // Wink.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class Wink: Form
  9. {
  10.      protected Image[] aimage  = new Image[4];
  11.      protected int     iImage = 0, iIncr = 1;
  12.  
  13.      public static void Main()
  14.      {
  15.           Application.Run(new Wink());
  16.      }
  17.      public Wink()
  18.      {
  19.           Text = "Gui±o";
  20.           ResizeRedraw = true;
  21.           BackColor = Color.White;
  22.  
  23.           for (int i = 0; i < 4; i++)
  24.                aimage[i] = new Bitmap(GetType(), 
  25.                                       "Wink.Eye" + (i + 1) + ".png");
  26.           Timer timer = new Timer();
  27.           timer.Interval = 100;
  28.           timer.Tick += new EventHandler(TimerOnTick);
  29.           timer.Enabled = true;
  30.      }
  31.      protected virtual void TimerOnTick(object obj, EventArgs ea)
  32.      {
  33.           Graphics grfx = CreateGraphics();
  34.  
  35.           grfx.DrawImage(aimage[iImage], 
  36.                         (ClientSize.Width  - aimage[iImage].Width)  / 2,
  37.                         (ClientSize.Height - aimage[iImage].Height) / 2,
  38.                         aimage[iImage].Width, aimage[iImage].Height);
  39.           grfx.Dispose();
  40.  
  41.           iImage += iIncr;
  42.  
  43.           if (iImage == 3)
  44.                iIncr = -1;
  45.           
  46.           else if (iImage == 0)
  47.                iIncr = 1;
  48.      }
  49. }
  50.